package org.btik.bean.impl;

import org.btik.context.AppContext;
import org.btik.light.tool.type.CollectionUtil;

import java.util.List;


public class LightContext implements AppContext {

    @Override
    public <T> T getBean(String beanId) {
        return (T) BeanCache.idMap.get(beanId);
    }

    @Override
    public <T> List<T> getBeans(Class<T> requiredType) {
        String typeName = requiredType.getName();
        List<Object> objects = BeanCache.typeMap.get(typeName);
        if (CollectionUtil.isEmpty(objects)) {
            return null;
        }
        return (List<T>) objects;
    }

    @Override
    public <T> T getBean(Class<T> requiredType) {
        String typeName = requiredType.getName();
        List<Object> objects = BeanCache.typeMap.get(typeName);
        if (CollectionUtil.isEmpty(objects)) {
            return null;
        }
        return (T) objects.get(0);
    }

    public LightContext() {
        this(null);
    }

    public LightContext(String path) {
        new BeanParser(path);

    }


}
